package com.chacha.utils;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ConnectionUtil {
	private static DataSource getDataSource(String jndi) {
		Context ctx;
		try {
			ctx = new InitialContext();
			return (DataSource) ctx.lookup(jndi);
		} catch (NamingException e) {
			e.printStackTrace();
		}
		//test
		return null;
	}
	
	public static Connection getConnection(String jndi) throws SQLException{
		DataSource ds = getDataSource(jndi);
		Connection con = ds.getConnection();
		return con;
	}
}
